//...
#include <algorithm>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <set>
#include <map>

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>

using namespace std;

int t, n, m, i, j, a, b, indeg[100], r[100];
bool dep[100][100];
vector<int> v[100];
queue<int> q;
void read(){
	scanf("%d%d", &n, &m);
	
	for(i=0;i<n;++i)v[i].clear();
	memset(indeg, 0, sizeof(indeg));
	memset(dep, 0, sizeof(dep));
	
	for(i=0;i<m;++i){
		scanf("%d%d", &a, &j);
		--a;
		while(j--){
			scanf("%d", &b);
			--b;
			indeg[b]++;
			v[a].push_back(b);
			dep[a][b]=1;
		}
	}
}

void process(){
	for(i=n-1;i>=0;--i){
		if(!indeg[i])q.push(i);
	}
	n=0;
	while(!q.empty()){
		a=q.front();q.pop();
		r[n++]=a;
		for(i=0;i<v[a].size();++i){
			indeg[v[a][i]]--;
			if(!indeg[v[a][i]])q.push(v[a][i]);
		}
	}
	for(i=n-1;i>0;--i){
		for(j=i-1;(j>=0)&&(!dep[r[j]][r[i]])&&(r[i]>r[j]);--j){
			swap(r[i],r[j]);
		}
	}
	printf("%d", r[n-1]+1);
	for(i=n-2;i>=0;--i)printf(" %d", r[i]+1);
	printf("\n");
}

int main(){
	//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);
	
	scanf("%d", &t);
	while(t--){
		read();
		process();
		if(t)printf("\n");
	}
	return 0;
}
